
/* Generated by Interface Builder */

#import "WozView.h"
#import "hgrconv.h"
#import <appkit/graphics.h>
#import <appkit/NXBitmapImageRep.h>
#import <appkit/tiff.h>
#import <string.h>

@implementation WozView

- initFrame:(const NXRect *) frameRect
{
  [super initFrame:frameRect];

  memset (fbuf, 0, sizeof fbuf);            /* Clear to black. */
  return self;
}

- drawSelf:(const NXRect *) rects: (int) rectCount
{
  NXImageBitmap (&bounds, 280, 192, 2, 1, NX_MESHED, NX_MONOTONICMASK, fbuf,
		 NULL, NULL, NULL, NULL);
  
  return self;
}


- drawChangedAreas:(const unsigned char *) a2_screen
                   shadow:(unsigned char *) a2_shadow
{
  unsigned char changed[192 / 16];
  NXRect r = bounds;
  int i, start, height;

  [self lockFocus];

  /* Find out what areas changed, if any. */
  if (find_changed_areas (a2_screen, a2_shadow, changed))
    {
      for (i = 0; i < sizeof changed; i++)
	if (changed[i])
	  {
	    start = i * 16;
	    for (i++; i < sizeof changed && changed[i]; i++);
	    height = i * 16 - start;
	    r.origin.y = (192 - (start + height)) * 2.0;
	    r.size.height = height * 2.0;  /*  * 2.0 since we are scaled. */
	    apple_to_next (a2_screen, fbuf, start, height);
	    NXImageBitmap (&r, 288, height, 2, 1, NX_MESHED, NX_MONOTONICMASK,
			   &fbuf[start][0], NULL, NULL, NULL, NULL);
	  }
      copy_changed_areas (a2_screen, a2_shadow, changed);
    }

  [self unlockFocus];

  return self;
}


- (unsigned char *) data
{
  return &fbuf[0][0];
}


- appDidInit:(id) sender
{
  char *foo = "a2";
  extern id screen_wozview;
  extern unsigned char *wozview_buf;

  screen_wozview = self;
  wozview_buf = &fbuf[0][0];

  simulator_main (1, &foo);
  return self;
}

@end

